<?php
    class Category_Model extends CI_Model
    {
        var $table = "db_categories";
        var $table_product = "db_product";
        function __construct()
        {
            parent::__construct();
        }
         function list_category_parent()
        {
            $this->db->where('id_parent',0);
            $this->db->order_by("order_cats", "asc"); 
            $this->db->where('active',1);
            return $this->db->get($this->table)->result();
        }
        function list_category_childrent()
        {
            //$this->db->where('id_parent',$id);
            $this->db->order_by("order_cats", "asc"); 
            $this->db->where('active',1);
            return $this->db->get($this->table)->result();
           
        }
        function show_product($id = null)
        {
            $this->db->order_by("order_product", "asc"); 
            $this->db->where('active',1);
            if($id != null)
            {
                $this->db->where('id_product',$id);
            }            
            return $this->db->get($this->table_product)->result();
           
        }
        function show_product_home()
        {
             $this->db->order_by("order_product", "asc"); 
            $this->db->where('active',1);
            $this->db->where('vitri_show',1);                     
            return $this->db->get($this->table_product)->result();
           
        }
        function show_product_left()
        {
             $this->db->order_by("order_product", "asc"); 
            $this->db->where('active',1);
            $this->db->where('vitri_left',1);                     
            return $this->db->get($this->table_product)->result();
           
        }
        function show_product_right()
        {
             $this->db->order_by("order_product", "asc"); 
            $this->db->where('active',1);
            $this->db->where('vitri_right',1);                     
            return $this->db->get($this->table_product)->result();
           
        }
        function show_product_slidershow()
        {
             $this->db->order_by("order_product", "asc"); 
            $this->db->where('active',1);
            $this->db->where('slidershow',1);                     
            return $this->db->get($this->table_product)->result();
           
        }
		function get_url_cat2($url)
		{
			$q = $this->db->get_where($this->table,array('url'=>$url));
			if($q->num_rows() > 0)
			{
				return $q->row()->id_cats;
			}
			else
			{
				return false;
			}
            $q->free_result();
		}
		function get_name_cats($url)
		{
			$q = $this->db->get_where($this->table,array('url'=>$url));
			if($q->num_rows() > 0)
			{
				return $q->row()->name_cats;
			}
			else
			{
				return false;
			}
             $q->free_result();
		}
		function show_product_cats($id,$id_product = null)
		{
		   $this->db->order_by("order_product", "asc"); 
			$this->db->where('id_cats',$id); 
			if($id_product != null)
			{
				$this->db->where('id_product !=',$id_product); 
			}
            return $this->db->get($this->table_product)->result();
           
		}
		function get_product_id($id)
		{
			$this->db->where('id_product',$id);                     
            return $this->db->get($this->table_product)->row();
           
		}
		function insert_order($data)
		{
			$data = array(
			'fullname'=>$data['fullname'],
			'phone'	  => $data['phone'],
			'address'	=> $data['address'],
			'comment'	=> $data['comment'],
			'date_order'	=> $data['date_order'],
			'id_product'	=> $data['id_product'],
			'soluong'		=> $data['soluong']			
			);
			$this->db->set($data);
			if($this->db->insert('db_orders')) return true; else return false;
		}
    }
?>